import time

from selenium.webdriver.common.by import By

from selenium.webdriver.support.select import Select

from conn.comm import wait_element



class HOME_page:
    def __init__(self):
        #实例化
        self.we = wait_element()
        # 点击学校管理
        self.school_management = By.XPATH,"/html/body/div[1]/div[3]/div[1]/div/div/div[2]/ul/li[1]/div/div"
        # 点击校园接入
        self.attc = By.XPATH,"//*[text()='校园接入']"
        #切换iframe到校园接入
        self.if1 = By.CSS_SELECTOR,"#mainFrame3"
        # 点击接入
        self.school_add = By.XPATH,'//*[@id="form1"]/div[2]/div/div/div/div/div/div/div[4]'
        #切换ifram，ifram的元素对象
        self.ifr = By.CSS_SELECTOR,"#layui-layer-iframe1"
        #输入学校名称
        self.school_name = By.CSS_SELECTOR,"#tbSchoolName"
        #输入学校编号
        self.school_code = By.CSS_SELECTOR,"#tbBaseId"
        #选择框  省份
        self.s1 =By.XPATH,"//*[@id='sheng' and @name='sheng']"
        #选择框  市
        self.s2 = By.XPATH, "//*[@id='shi' and @name='shi']"
        #选择框  区
        self.s3 = By.XPATH, "//*[@id='qu' and @name='qu']"
        #学校阶段下拉框
        self.s4 = By.XPATH,"//*[@id='tbSchooljd' and @name='schooljd']"
        #校管理员姓名
        self.school_g_name = By.XPATH,"//*[@id='tbLinkman' and @name='realname']"
        #电话号码
        self.school_phone = By.XPATH,"//*[@id='tbPhone' and @name='mobilenum']"
        #点击保存
        self.save_school = By.XPATH,"//*[@id='btn_Save']"

    def add_school(self,driver,school_name,school_code,school_g_name="肖和坚",school_g_phone="13833138221",sf=1,sj=1,q='东城区',xz='小学'):
        '''
        学校接入
        :param driver:
        :param school_name: 学校名称
        :param school_code: 学校编号
        :param sf: 省份
        :param sj: 市
        :param q: 区县
        :param xz: 学校阶段
        :param school_g_name: 学校管理员名称
        :param school_g_phone: 学校管理员账号（电话号码）
        :return:
        '''
        #点击学校管理  校园接入  接入
        self.we.look_wait(driver,*self.school_management).click()
        self.we.look_wait(driver,*self.attc).click()
        ifr1 = self.we.look_wait(driver,*self.if1)
        driver.switch_to.frame(ifr1)
        self.we.look_wait(driver, *self.school_add).click()
        # 切换iframe
        self.ifrrr = self.we.look_wait(driver,*self.ifr)
        driver.switch_to.frame(self.ifrrr)
        #输入学校名称，学校编号，选择地区，选择学制
        self.we.send_ele(self.we.look_wait(driver,*self.school_name),school_name)
        self.we.send_ele(self.we.look_wait(driver,*self.school_code),school_code)
        ss1 = Select(self.we.look_wait(driver,*self.s1))
        ss1.select_by_index(sf)
        ss2 = Select(self.we.look_wait(driver,*self.s2))
        time.sleep(3)
        ss2.select_by_index(sj)
        ss3 = Select(self.we.look_wait(driver,*self.s3))
        time.sleep(3)
        ss3.select_by_visible_text(q)
        s_s1 = Select(self.we.look_wait(driver,*self.s4))
        time.sleep(3)
        s_s1.select_by_visible_text(xz)
        #学校管理员姓名及电话
        self.we.send_ele(self.we.look_wait(driver,*self.school_g_name),school_g_name)
        self.we.send_ele(self.we.look_wait(driver,*self.school_phone),school_g_phone)
        #点击保存
        self.we.look_wait(driver,*self.save_school).click()















